const fs = require("fs")
const execa = require("execa")

// 获取包名 ["reactivity", "shared"]
const targets = fs.readdirSync("packages").filter(f => fs.statSync(`packages/${f}`).isDirectory())

function runParallel(targets, iteratorFn) {
  let res = []
  for (const item of targets) {
    const p = iteratorFn(item)
    res.push(p)
  }
  return Promise.all(res)
}

// 运行
async function build(target) {
  await execa("rollup", ["-c", "--environment", `TARGET:${target}`], { stdio: "inherit" })
}

runParallel(targets, build)
